local ClientOHOH = _G.ClientOHOH;

-- local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHOLYBUIBase());
local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHScreenBase());
local CallBackManager = ClientOHOH.load.CallBackManager();
local ConnectClass=_G.CommonOHOH.load.Connect();
local BtnHelper = ClientOHOH.load.BtnHelper();
local LanguageHelper=_G.LanguageHelper;
local PetTool=_G.CommonOHOH.load.PetTool();

-- function InitInsts(ui)
-- 	ui.insts = { }
-- 	ui.insts.root = "ctrl.slotlist.root"
-- end;
function M.new(...)
	return M(...);
end;

function M.GuiButton(self,uiObj)
	for _, v in pairs(uiObj:GetDescendants()) do
		if v:IsA("GuiButton") then
			BtnHelper:InitButton(v, nil, nil, nil, function() end);
		end;
	end;
end

local copy=ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.UI.PetVoidGui.Frame.Frame.slotlist.cell")

function M.ctor(self,id,parent)
	M.super.ctor(self, copy:Clone())
	-- InitInsts(self.main_inst)
	self.main_inst.Parent=parent
	self.main_inst.Name = "SlotCopy" .. id 
	self.main_inst.Visible=true
	self.main_inst:SetAttribute("Empty", true)
	self.orderId = id
	self.petId = nil
	self.guid = nil
	self.needTime = math.huge
	self.startTime = 0
	self.hadBuy = false
	self.MakeClickEvent=ConnectClass.new();  
	self.BuyClickEvent=ConnectClass.new();  
	self.ReceiveClickEvent=ConnectClass.new();
	--self.main_inst.idleBtn.Activated
	CallBackManager:AddRbxConnect(self,self.main_inst.idleBtn.Activated, function()
		self.MakeClickEvent:Action(self)
	end);
	CallBackManager:AddRbxConnect(self,self.main_inst.progressBtn.Activated, function()
		self.BuyClickEvent:Action(self)
	end);
	CallBackManager:AddRbxConnect(self,self.main_inst.receiveBtn.Activated, function()
		--self.MakeClickEvent:Action(self)
		self.ReceiveClickEvent:Action(self)

		--self.main_inst.ViewportFrame.Model:Destroy()
		--self.main_inst.idle.Visible = true
		--self.main_inst.idleBtn.Visible = true
		--self.main_inst.receive.Visible = false
		--self.main_inst.receiveBtn.Visible =  false
		--self.needTime = 0
		--self.main_inst.progress.time.Text =  self.voidTimeToHHMMSS(math.huge)
		--self.main_inst:SetAttribute("Empty", true)
	end);

	self:init()

end;

function M.init(self)

end
function M.Update(self)
	if(self.needTime<=0) and self.update_connect then
		--结束倒计时
		self.update_connect:Disconnect();
		self.update_connect=nil;
		self.main_inst.progress.Visible = false
		self.main_inst.progressBtn.Visible = false
		self.main_inst.receive.Visible = true
		self.main_inst.receiveBtn.Visible =  true
	end
	local min=math.huge;
	self.needTime=self.needTime-1;
	min=self.needTime;
	local timeStr=self.voidTimeToHHMMSS(min)
	self.main_inst.progress.time.Text =  timeStr
	if(self.needTime==0)then
		--结束倒计时
		self.update_connect:Disconnect();
		self.update_connect=nil;
		self.main_inst.progress.Visible = false
		self.main_inst.progressBtn.Visible = false
		self.main_inst.receive.Visible = true
		self.main_inst.receiveBtn.Visible =  true
	end
end
function M.StartUpdateTime(self)
	if self.update_connect then
		return 
	end

	self.update_connect=self:AddStepUpdate(self.Update,1)
end
--function M.EndUpdateTime(self)
--	if not self.update_connect then
--		return 
--	end

--	self.update_connect:Disconnect();
--	self.update_connect=nil;
--end
function M.voidTimeToHHMMSS(voidTime)
	local hours = math.floor(voidTime / 3600)
	local minutes = math.floor((voidTime % 3600) / 60)
	local seconds = voidTime - hours*3600 - minutes*60
	return string.format("%02d:%02d:%02d", hours, minutes , seconds)
end

function M.dtor(self)
	local obj=self.main_inst
	-- self.main_inst:Destroy()
	M.super.dtor(self);
	obj:Destroy()
end;




--********************************************************************************

--以下是接口

-------------各种标记----锁定，准备，选择，删除（售卖）------------------------------------------------
--设置选中状态(true,会出现红桃)


----------------标签End----------------------------


-----------------宠物信息相关-----------------------------
-- 获取段位颜色参数：段位Id

------------------宠物信息-End--------------------------------------

----------------------其它接口--------------------------------

function M.GetGuid(self)
	return  self.guid
end

function M.GetPetId(self)
	return  self.petId
end

--更新Size


-- 返回cell的绝对坐标
--function M.GetAbsolutePosition(self)
--	return self.main_inst.AbsolutePosition
--end

----获取cell所在的ScreenGui
--function M.GetRootGui(self)
--	if not  self.RootGui then
--		self.RootGui=self.main_inst:FindFirstAncestorOfClass("ScreenGui")
--	end
--	return self.RootGui
--end



return M